<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;

class OrderController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
       $db = \DB::table("order");
	   //判断并封装搜索条件
	   $params = array();
	   
	   if(!empty($_GET['orderForm'])){
		   $db->where("orderForm","like","%{$_GET['orderForm']}%");
		   $params['orderForm'] = $_GET['orderForm']; //维持搜索条件
	   }
       $list = $db->paginate(5); //5条每页浏览
        
       return view("admin.order.index",['list'=>$list,'params'=>$params]);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
	//进行审核操作
    public function create(Request $request)
    {
		//获取要更改数据的id
		$id = $_GET['id'];
        //进行数据库更新操作
        \DB::table("order")->where("id",$id)->update(['status'=>3]);
		$db = \DB::table("order");
		$list = $db->paginate(5); //5条每页浏览
		$params = array();
		return view("admin.order.index",['list'=>$list,'params'=>$params]);
	
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
	//后台订单详情
    public function show($id)
    {
        $data = \DB::table("order")->where("id",$id)->first();
		$addr = \DB::table("address")->where("id",$data->aid)->first();
		$addr1 = $addr->province."&nbsp;&nbsp;".$addr->city."&nbsp;&nbsp;".$addr->area."&nbsp;&nbsp;".$addr->xiang."&nbsp;&nbsp;".$addr->street;
		return view("admin/order/show",['list'=>$data,"addr"=>$addr,"addr1"=>$addr1]);
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
	//后台订单编辑
    public function edit($id)
    {
        $data = \DB::table("order")->where("id",$id)->first();
		$addr = \DB::table("address")->where("id",$data->aid)->first();
		$addr1 = $addr->province."&nbsp;&nbsp;".$addr->city."&nbsp;&nbsp;".$addr->area."&nbsp;&nbsp;".$addr->xiang."&nbsp;&nbsp;".$addr->street;
		return view("admin.order.edit",['list'=>$data,"addr"=>$addr,"addr1"=>$addr1]);
    }

	 public function edits($id)
    {
		return "aa";
    }
    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
		\DB::table("order")->where("id",$id)->update(["num"=>$request->num,"pName"=>$request->pName,"address"=>$request->address,"post"=>$request->post,"phone"=>$request->phone]);
		$db = \DB::table("order");
		$list = $db->paginate(5); //5条每页浏览
		//return view("admin.order.index",['list'=>$list]);
		 return redirect("admin/order");
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        \DB::table('order')->delete($id);
        return redirect("admin/order");
    }
}
